<!doctype html>
<html>
{include file="./public/admin/common/head_css.html" /}
<body>
{include file="./public/admin/common/header.html" /}
<div class="container clearfix">
    {include file="./public/admin/common/left.html" /}
    <!--/sidebar-->
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/jscss/admin/design/">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/jscss/admin/design/">作品管理</a><span class="crumb-step">&gt;</span><span>新增作品</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="" method="post" id="myform" name="myform" enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody>
                        <tr>
                            <th width="120"><i class="require-red">*</i>分类：</th>
                            <td>
                                <select name="colId" id="catid" class="required">
                                    {volist name='write' id='w' }
                                    {if condition = "$w.pid eq 0 and $w.del eq 1"}
                                    <option value="{$w.id}">{$w.title}</option>
                                    {/if}
                                    {/volist}
                                </select>
                            </td>
                        </tr>
                            <tr>
                                <th><i class="require-red">*</i>标题：</th>
                                <td>
                                    <input class="common-text required" id="title" name="title" size="50" value="" type="text">
                                </td>
                            </tr>

                            <tr>
                                <th><i class="require-red">*</i>缩略图：</th>
                                <td>
                                    <input name="token" id="token" value="FFFX123456" type="hidden">
                                    <button type="button" class="layui-btn" id="test1">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <em  id="a">

                                    </em>

                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>内容：</th>
                                <td><textarea name="content" class="common-textarea" id="content" cols="30" style="width: 98%;display: none" rows="10"></textarea></td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" id="add-btn"  type="submit" lay-submit="" lay-filter="add-btn">
                                    <!--<button class="btn btn-primary btn6 mr10" id="add-btn" lay-submit="" lay-filter="add-btn">-->
                                    <input class="btn btn6" onClick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
</body>
{include file="./public/admin/common/JS.html" /}
<script>
    var layedits = [];
    var img = [];
    layui.use('layedit', function(data){
        var layedit = layui.layedit;
        var token ='FFFX123456';
         layedit.set({
             uploadImage:{
                 url: url_list.upload,
                 data:{'token':token},
                 type:'post',
             }
         });
        layedits.push(layedit.build('content')); //建立编辑器
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        upload.render({
            elem: '#test1' //绑定元素
            ,url:url_list.upload //上传接口
            ,data:{'token':'FFFX123456'}
            ,done: function(res){
                //上传完毕回调
                console.log(res);
                img.push(res.data.savepath);
                layer.msg(res.msg, {icon: 1, time: 1500});
                $("#a").html('<img style="height: 25px" src="__static__/images/check.png" >');
            }
            ,error: function(){
                //请求异常回调
                layer.msg(res.msg, {icon: 2, time: 1500});

            }
        });
    });

    layui.use(['form'],function () {

        var form = layui.form;
        form.on('submit(add-btn)', function(data) {
            if (img[0]==undefined ||img[0]==''){
                layer.msg('请上传图片', {icon: 2, time :1500});
            }else{
                var content = layui.layedit.getContent(layedits[0]);
                var title = $('#title').val();
                var pid = $('#catid').val();
                //验证签名
                sign.params = {
                    pid: pid,
                    title: title,
                    content: content,
                    img: img[0]
                }
                var encode_data = sign.encode_post();
                console.log(encode_data);
                $.post(url_list.writing,encode_data,function (data) {
                    //解码
                    if(typeof data == 'string'){
                        data = eval('('+data+')');
                    }
                    data = sign.decode_post(data);
                    console.log(data);
                    if (data.code == 200) {
                        layer.msg(data.msg, {icon: 1, time: 1500});
                        myArticleList();
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                });
            }return false;
        });
    })

</script>
</html>